package com.ruoyi.quartz.task;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.SysAccount;
import com.ruoyi.system.domain.SysDo;
import com.ruoyi.system.domain.SysStudy;
import com.ruoyi.system.domain.SysTotal;
import com.ruoyi.quartz.mapper.SysJobMapper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{

    @Resource
    private SysJobMapper sysJobMapper;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }

    @Transactional
    public void huizong()
    {
        String beforeYearMouth = DateUtils.getBeforeYearMouth();
        //获得所有罪犯
        List<SysUser> sysUsers = sysJobMapper.selectAllUser();
        //获取其他数据
        for (SysUser sysUser : sysUsers) {
            Long getstudy = sysJobMapper.getstudy(sysUser.getUserId(), beforeYearMouth);
            Long aDo = sysJobMapper.getDo(sysUser.getUserId(), beforeYearMouth);
            Long account = sysJobMapper.getAccount(sysUser.getUserId());
            SysTotal sysTotal = new SysTotal();
            sysTotal.setUserId(sysUser.getUserId());
            sysTotal.setUserName(sysUser.getNickName());
            sysTotal.setAccountMoney(account);
            sysTotal.setDoMoney(aDo);
            sysTotal.setStudyMoney(getstudy);
            sysTotal.setTotalMouth(beforeYearMouth);
            Date date = new Date();
            sysTotal.setCreateTime(date);
            sysJobMapper.insertSysTotal(sysTotal);
        }
        //插入操作
        new ArrayList<SysTotal>();
    }
}
